import $https from '@/api/https'
export default {
  namespaced: true,
  state: {
    CurrentCoachInfo: {},   // 当前教练信息
    CoachStudentInfo: [],   // 分页获取的学员信息
    AllCoachStudentInfo: [],// 所有学员信息 -- 该教练的
  },
  mutations: {
    setCurrentCoachInfo(state, val) {
      state.CurrentCoachInfo = val
    },
    setCoachStudentInfo(state, val) {
      state.CoachStudentInfo = val
    },
    setAllCoachStudentInfo(state, val) {
      state.AllCoachStudentInfo = val
    },
  },
  actions: {
    // 根据教练的 identify 属性获取教练信息
    async getCurrentCoachInfo(context) {
      const { data } = await $https.getUserData({
        url: "/coach",
        identify: JSON.parse(localStorage.getItem("token")).username,
      });
      context.commit("setCurrentCoachInfo", data[0])
    },
    // 分页获取教练带领学员数据
    async getCoachStudentInfoByPaging(context, obj) {
      const { data } = await $https.getUserData(obj)
      context.commit("setCoachStudentInfo", data)
    },
    // 获取所有由教练带领的学员数据
    async getAllCoachStudentInfo(context, obj) {
      const { data } = await $https.getUserData(obj)
      context.commit("setAllCoachStudentInfo", data)
    },
    // 获取搜索后的学员数据
    async getSearchedCoachStudentInfo(_, obj) {
      const { data } = await $https.getUserData(obj)
      return data
    },
    async getAllCarInfo(_, obj) {
      const { data } = await $https.getCar(obj)
      return data
    },
  }
}